<?php


function generateQrcode($text): string
{
    if (!$text) {
        return '';
    }
    $config         = get_addon_config('qrcode');
    $params         = [];
    $params['text'] = $text;
    $qrCode         = \addons\qrcode\library\Service::qrcode($params);
    // 写入到文件
    if ($config['writefile']) {
        $qrcodePath = ROOT_PATH . 'public/uploads/qrcode/' . date('Ymd') . '/';
        if (!is_dir($qrcodePath)) {
            @mkdir($qrcodePath);
        }
        if (is_really_writable($qrcodePath)) {
            $filePath = $qrcodePath . md5(implode('', $params)) . '.' . $config['format'];
            $qrCode->writeFile($filePath);
            $key        = md5(implode('', $params)) . '.' . $config['format'];
            $returnPath = '/uploads/qrcode/' . date('Ymd') . '/' . $key;
        }
    }
    return $returnPath ?? '';
}
